import 'package:hm_show_flutter/entity/goods.dart';
import 'package:hm_show_flutter/entity/share.dart';

class GoodsDetailEntity {
  int errno;
  GoodsDetailData data;
  String errmsg;

  GoodsDetailEntity({this.errno, this.data, this.errmsg});

  GoodsDetailEntity.fromJson(Map<String, dynamic> json) {
    errno = json['errno'];
    data = json['data'] != null
        ? new GoodsDetailData.fromJson(json['data'])
        : null;
    errmsg = json['errmsg'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['errno'] = this.errno;
    if (this.data != null) {
      data['data'] = this.data.toJson();
    }
    data['errmsg'] = this.errmsg;
    return data;
  }
}

class GoodsDetailData {
  GoodsDetailDataProduct product;

  GoodsDetailData({this.product});

  GoodsDetailData.fromJson(Map<String, dynamic> json) {
    product = json['product'] != null
        ? new GoodsDetailDataProduct.fromJson(json['product'])
        : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.product != null) {
      data['product'] = this.product.toJson();
    }
    return data;
  }
}

class GoodsDetailDataProduct {
  bool isRecommend;
  String code;
  bool isCollection;
  String description;
  String url;
  List<String> urls;
  double price;
  String name;
  bool isPopular;
  int id;
  List<GoodsDetailDataProductAttach> attach;
  List<GoodsDetailDataProductParametermap> parameterMap;
  dynamic collectionId;
  ShareModel share;

  GoodsDetailDataProduct(
      {this.isRecommend,
      this.code,
      this.isCollection,
      this.description,
      this.url,
      this.urls,
      this.price,
      this.name,
      this.isPopular,
      this.id,
      this.attach,
      this.parameterMap,
      this.collectionId,
      this.share});

  GoodsDetailDataProduct.fromJson(Map<String, dynamic> json) {
    isRecommend = json['isRecommend'];
    code = json['code'];
    isCollection = json['isCollection'];
    description = json['description'];
    url = json['url'];
    urls = json['urls']?.cast<String>();
    price = json['price'];
    name = json['name'];
    isPopular = json['isPopular'];
    id = json['id'];
    if (json['attach'] != null) {
      attach = new List<GoodsDetailDataProductAttach>();
      (json['attach'] as List).forEach((v) {
        attach.add(new GoodsDetailDataProductAttach.fromJson(v));
      });
    }
    if (json['parameterMap'] != null) {
      parameterMap = new List<GoodsDetailDataProductParametermap>();
      (json['parameterMap'] as List).forEach((v) {
        parameterMap.add(new GoodsDetailDataProductParametermap.fromJson(v));
      });
    }
    collectionId = json['collectionId'];
    share =
        json['share'] != null ? new ShareModel.fromJson(json['share']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['isRecommend'] = this.isRecommend;
    data['code'] = this.code;
    data['isCollection'] = this.isCollection;
    data['description'] = this.description;
    data['url'] = this.url;
    data['urls'] = this.urls;
    data['price'] = this.price;
    data['name'] = this.name;
    data['isPopular'] = this.isPopular;
    data['id'] = this.id;
    if (this.attach != null) {
      data['attach'] = this.attach.map((v) => v.toJson()).toList();
    }
    if (this.parameterMap != null) {
      data['parameterMap'] = this.parameterMap.map((v) => v.toJson()).toList();
    }
    data['collectionId'] = this.collectionId;

    if (this.share != null) {
      data['share'] = this.share.toJson();
    }
    return data;
  }
}

class GoodsDetailDataProductAttach {
  String subtitle;
  List<GoodsModel> xList;

  GoodsDetailDataProductAttach({this.subtitle, this.xList});

  GoodsDetailDataProductAttach.fromJson(Map<String, dynamic> json) {
    subtitle = json['subtitle'];
    if (json['list'] != null) {
      xList = new List<GoodsModel>();
      (json['list'] as List).forEach((v) {
        xList.add(new GoodsModel.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['subtitle'] = this.subtitle;
    if (this.xList != null) {
      data['list'] = this.xList.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class GoodsDetailDataProductParametermap {
  String name;
  String value;

  GoodsDetailDataProductParametermap({this.name, this.value});

  GoodsDetailDataProductParametermap.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    value = json['value'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    data['value'] = this.value;
    return data;
  }
}
